package edu.dayu.controller;

import com.github.pagehelper.PageInfo;
import edu.dayu.pojo.Club;
import edu.dayu.service.ClubService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/admin")
public class ClubController {
    @Autowired
    private ClubService clubService;

    @PostMapping("/clubInsert")
    public boolean clubInsert(Club club){
        return clubService.clubInsert(club);
    }

    @PostMapping("/clubList")
    public PageInfo<Club> clubList(Club club){
        return clubService.clubList(club);
    }

    @PostMapping("/clubById")
    public Club clubById(Club club){
        PageInfo<Club> clubPageInfo = clubService.clubList(club);
        List<Club> list = clubPageInfo.getList();
        Club club1 = new Club();
        for (Club club2 : list) {
            club1 = club2;
        }
        return club1;
    }

    @PostMapping("/clubUpdate")
    public void clubUpdate(Club club){
        clubService.clubUpdate(club);
    }

    @PostMapping("/clubDelete")
    public void clubDelete(Club club){
        clubService.clubDelete(club);
    }


    @PostMapping("/clubByName")
    Club clubByName(String name){
        return clubService.clubByName(name);
    }
}
